package com.atguigu.myjuc.mythread.day2;
//100个线程加100次

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

class Count {
    int number = 100;

    public int getNumber() {
        return number;
    }

    public synchronized void setNumber() {
        number++;
    }
}
     class setAtomic {
    public static AtomicInteger atomicInteger = new AtomicInteger();
    int sNumber = 100;

    public int getsNumber() {

        return atomicInteger.get();
    }

    public void setsNumber() {
        atomicInteger.incrementAndGet();
    }


}
public class CASDemo {



    public static void main(String[] args) throws InterruptedException {

        int MAX=100;
        CountDownLatch countDownLatch=new CountDownLatch(MAX);
       Count count = new Count();
        setAtomic setAtomic = new setAtomic();
        for (int i = 0; i <= 100; i++) {
            new Thread(()->{
                for (int j = 0; j < MAX; j++) {
                   count.setNumber();
                    setAtomic.setsNumber();
                }
                countDownLatch.countDown();

            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(count.getNumber());
        System.out.println(setAtomic.getsNumber());
    }


}
